package com.szh.shenzhihaodemo.Adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.szh.shenzhihaodemo.Bean.UserInfoBean;
import com.szh.shenzhihaodemo.R;

import java.util.List;

public class ManagerAdapter extends BaseAdapter {
    private static final String TAG = "ManagerAdapter";
    Context context;
    List<UserInfoBean>mDatas;

    public ManagerAdapter(Context context, List<UserInfoBean> mDatas) {
        this.context = context;
        this.mDatas = mDatas;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_manager_lv,null);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        UserInfoBean bean = mDatas.get(position);
        notifyDataSetChanged();
        holder.name.setText(bean.getName());
        holder.pwd.setText(bean.getPwd());
        String sex = bean.getSex();
        Log.d(TAG, "sex: "+sex);
        if (!TextUtils.isEmpty(sex)) {
            holder.sex.setVisibility(View.VISIBLE);
            holder.sex.setText(sex);
        }
        return convertView;
    }
    class ViewHolder{
        TextView name,pwd,sex;
        public ViewHolder(View view){
            name=view.findViewById(R.id.item_manager_name);
            pwd=view.findViewById(R.id.item_manager_pwd);
            sex=view.findViewById(R.id.item_manager_sex);
        }
    }
}
